package net.lb.socketserver.transfer.server;

import net.lb.baseutil.collection.set.LightSet;
import net.lb.socketserver.util.DefaultHeadFactory;
import net.lb.socketserver.util.HeadFactory;

/**
 * 服务器的配置类，用以配置初始化服务器的信息。
 * 其中默认读取超时为3秒，空闲等待为30秒
 * 
 * @author 林斌（windfire@zailanghua.com）
 * 
 */
public class ServerConfig
{
    private byte[]           publicKey;
    // 链接空闲时的等待时间，默认为30秒
    private long             waitTimeout     = 30000;
    // 读取超时时间，默认为3秒
    private long             readTiemout     = 3000;
    // 服务器的启动端口
    private int              port;
    private LightSet<String> packageNamesSet = new LightSet<>();
    private HeadFactory      headFactory     = new DefaultHeadFactory();
    
    public long getWaitTimeout()
    {
        return waitTimeout;
    }
    
    public void setWaitTimeout(long waitTimeout)
    {
        this.waitTimeout = waitTimeout;
    }
    
    public long getReadTiemout()
    {
        return readTiemout;
    }
    
    public void setReadTiemout(long readTiemout)
    {
        this.readTiemout = readTiemout;
    }
    
    public int getPort()
    {
        return port;
    }
    
    public void setPort(int port)
    {
        if (port < 0 || port > 63355)
        {
            throw new RuntimeException("设定的端口号异常，超出了系统范围");
        }
        this.port = port;
    }
    
    public String[] getPackageNames()
    {
        return packageNamesSet.toArray(String.class);
    }
    
    public byte[] getPublicKey()
    {
        return publicKey;
    }
    
    public void setPublicKey(byte[] publicKey)
    {
        this.publicKey = publicKey;
    }
    
    /**
     * 设置包路径
     * 
     * @param packageNames
     */
    public void setPackageNames(String... packageNames)
    {
        packageNamesSet.removeAll();
        packageNamesSet.addAll(packageNames);
    }
    
    /**
     * 增加包路径
     * 
     * @param packageNames
     */
    public void addPackageNames(String... packageNames)
    {
        packageNamesSet.addAll(packageNames);
    }
    
    /**
     * 设置报文头部的生成和验证工厂类
     * 
     * @param headFactory
     * @author windfire(windfire@zailanghua.com)
     */
    public void setHeadFactory(HeadFactory headFactory)
    {
        this.headFactory = headFactory;
    }
    
    public HeadFactory getHeadFactory()
    {
        return headFactory;
    }
    
}
